package com.payment.web.controller.system;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.payment.system.util.GuangGuUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.payment.common.annotation.Log;
import com.payment.common.base.AjaxResult;
import com.payment.common.enums.BusinessType;
import com.payment.common.page.TableDataInfo;
import com.payment.common.utils.ExcelUtil;
import com.payment.framework.util.ShiroUtils;
import com.payment.framework.web.base.BaseController;
import com.payment.system.domain.Acq;
import com.payment.system.service.IAcqService;

/**
 * 通道 信息操作处理
 *
 * @author payment
 * @date 2019-01-01
 */
@Controller
@RequestMapping("/system/acq")
public class AcqController extends BaseController {
    private String prefix = "system/acq";

    @Autowired
    private IAcqService acqService;

    @RequiresPermissions("system:acq:view")
    @GetMapping()
    public String acq() {

        return prefix + "/acq";
    }

    /**
     * 查询通道列表
     */
    @RequiresPermissions("system:acq:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Acq acq) {
        startPage();
        List<Acq> list = acqService.selectAcqList(acq);
        return getDataTable(list);
    }


    /**
     * 导出通道列表
     */
    @RequiresPermissions("system:acq:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Acq acq) {
        List<Acq> list = acqService.selectAcqList(acq);
        ExcelUtil<Acq> util = new ExcelUtil<Acq>(Acq.class);
        return util.exportExcel(list, "acq");
    }

    /**
     * 新增通道
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        JSONObject jsonObject = null;
        try {
              jsonObject = GuangGuUtil.channelQuery();
              mmap.put("list",jsonObject.get("channels"));
        } catch (Exception e) {
            mmap.put("list","");
        }
        return prefix + "/add";
    }

    /**
     * 新增保存通道
     */
    @RequiresPermissions("system:acq:add")
    @Log(title = "通道", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Acq acq) {

        return acqService.insertAcq(acq, ShiroUtils.getUuid());
    }

    /**
     * 修改通道
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Acq acq = acqService.selectAcqById(id);
        mmap.put("acq", acq);
        return prefix + "/edit";
    }

    /**
     * 修改保存通道
     */
    @RequiresPermissions("system:acq:edit")
    @Log(title = "通道", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Acq acq) {
        return toAjax(acqService.updateAcq(acq));
    }

    /**
     * 删除通道
     */
    @RequiresPermissions("system:acq:remove")
    @Log(title = "通道", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(acqService.deleteAcqByIds(ids));
    }


    /**
     * 修改通道状态 启用或禁用
     */
    @PostMapping("/changeEmployStatus")
    @ResponseBody
    public AjaxResult changeEmployStatus(Acq acq) {
        return acqService.changeEmployStatus(acq);
    }

}
